package cn.shenlong.common;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

public class CustomBooleanTypeHandler implements TypeHandler<Boolean> {

	public Boolean getResult(ResultSet rs, String columnName)
			throws SQLException {
		boolean rtn = false;
		String tmp = rs.getString(columnName);
		if ("Y".equals(tmp))
			rtn = true;
		return rtn;
	}

	public void setParameter(PreparedStatement ps, int i, Boolean parameter,
			JdbcType jdbcType) throws SQLException {
		ps.setString(i, parameter ? "Y" : "N");
	}

	public Boolean getResult(ResultSet rs, int columnIndex) throws SQLException {
		boolean rtn = false;
		String tmp = rs.getString(columnIndex);
		if ("Y".equals(tmp))
			rtn = true;
		return rtn;
	}

	public Boolean getResult(CallableStatement cs, int columnIndex)
			throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
}
